﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DataTable
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //dataGridView1.Rows[2].Selected = true; //ustawia fokus na 2 wierszu
            //MessageBox.Show(dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + dataGridView1.SelectedRows[0].Cells[1].Value.ToString());

            //foreach (DataGridViewRow row in dataGridView1.Rows)
            //    MessageBox.Show(row.Cells[0].Value.ToString());

            foreach (DataGridViewRow check in dataGridView1.Rows)
            {
                if ((bool)check.Cells["bbb"].FormattedValue)
                {
                    //string Names = check.Cells["Names"].Value.ToString();
                    //string Mobile = check.Cells["Mobile"].Value.ToString();
                    MessageBox.Show(check.Cells[1].Value.ToString());

                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //string oradb = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=soil-festivities.wsisiz.edu.pl)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));User Id=roslanih;Password=karlson3;";
            //try
            //{
            //    OracleConnection conn = new OracleConnection(oradb);
            //    conn.Open();
            //    string sql = "SELECT id, imie FROM imie";
            //    OracleDataAdapter adapter = new OracleDataAdapter(sql, conn);
            //    DataSet set = new DataSet();
            //    adapter.Fill(set, "nazwa");
            //    dataGridView1.DataSource = set;
            //    //dataGridView1.DataBind();

            //}
            //catch (Exception exp)
            //{
            //    MessageBox.Show(exp.Message);
            //}

            System.Data.DataTable myDataTable = new System.Data.DataTable("myDataTable");
            DataColumn myDataColumn;
            DataRow myDataRow;
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "id";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "Item";
            myDataTable.Columns.Add(myDataColumn);

            DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
            {
                column.HeaderText = "aaa";
                column.Name = "bbb";
                column.AutoSizeMode =
                    DataGridViewAutoSizeColumnMode.DisplayedCells;
                column.FlatStyle = FlatStyle.Standard;
                column.ThreeState = true;
                column.DefaultCellStyle.NullValue = false;
                column.CellTemplate = new DataGridViewCheckBoxCell();
                column.CellTemplate.Style.BackColor = Color.Beige;
            }

            dataGridView1.Columns.Insert(0, column);

            for (int i = 0; i < 10; i++)
            {
                myDataRow = myDataTable.NewRow();
                myDataRow["id"] = i;
                myDataRow["item"] = "item " + i;
                myDataTable.Rows.Add(myDataRow);
            }
            dataGridView1.Rows.Add(new DataGridViewRow());
            dataGridView1.DataSource = myDataTable;
            dataGridView1.Columns["id"].Visible = false;

        }
    }
}
